﻿Imports ISNet.WebUI.WebTreeView
Imports log4net

Partial Class R07
    Inherits System.Web.UI.Page

    Public ScriptText As String = ""
    Private Shared logger As ILog = LogManager.GetLogger("R07")

    Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
        WebCombo3.EncodeOutput = True
    End Sub
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Label1.Text = "ระบบจัดทำงบประมาณ >> รายงาน >> รายงานวางแผนรายจ่ายดำเนินงาน"
        If Session("users") Is Nothing Then
            Response.Redirect("LoginForm.aspx")
        End If
        
        If IsPostBack = False Then
            DropDownList1.Items(0).Selected = True
            Session.Remove("FCTRgroup")
            Session("FCTRgroup") = DropDownList1.SelectedValue
            Try
                Dim adap As New DBdataTableAdapters.AppConfigsTableAdapter
                Dim dt As New DBdata.AppConfigsDataTable
                dt = adap.GetData
                For Each item As DBdata.AppConfigsRow In dt
                    Select Case item.Name
                        Case "ACTIVE_PLAN_YEAR"
                            PlanYearsTxt1.Text = item.Value
                            'VersionTxt1.Text = "1"
                            VersionCombo1.AdditionalFiltersText = "[PlanYear] = " & item.Value
                            VersionCombo1.Value = "1"
                            VersionCombo2.AdditionalFiltersText = "[PlanYear] = 0000"
                            VersionCombo3.AdditionalFiltersText = "[PlanYear] = 0000"
                            VersionCombo4.AdditionalFiltersText = "[PlanYear] = 0000"
                            VersionCombo5.AdditionalFiltersText = "[PlanYear] = 0000"
                    End Select
                Next
            Catch ex As Exception
                logger.Error(ex.Message)
                logger.Error(ex.StackTrace)
            End Try
        End If


        'Label1.Text = Date.Now.AddYears(543).Year
        'PlotNode()
        PlotCmmtNode()
    End Sub

    Sub PlotNode()

        Dim MyNode As WebTreeViewNode
        MyNode = New WebTreeViewNode()

        Dim adapter As New FundCenterParentTableAdapters.fctr_viewTableAdapter
        Dim dt As New FundCenterParent.fctr_viewDataTable
        dt = adapter.GetDataByUser(Session("users"), Val(Session("planyear")))

        Dim root_id As String

        MyNode.Text = "GSB"
        MyNode.Value = "0"
        root_id = "0"

        If dt.Count > 0 Then

            WebTreeView3.Nodes.Add(MyNode)

            Dim rootpath = ""
            rootpath = FctrClass.GetRoot(Session("users"), Val(Session("planyear")))
            Dim rootarr() As String = Split(rootpath, ",")
            WebTreeView3.Nodes.Add(MyNode)

            For i = 0 To rootarr.Length - 1
                PlotChild(rootarr(i), MyNode, 1)
            Next
        End If

    End Sub

    Sub PlotChild(ByVal gpath As String, ByRef cnode As WebTreeViewNode, ByVal level As Decimal)
        'Response.Write(gpath & "<br>")
        Dim Hadapter As New FundCenterParentTableAdapters.FctHTableAdapter
        Dim Hdatatable As New FundCenterParent.FctHDataTable
        Hdatatable = Hadapter.GetDataByGPath(gpath, Val(Session("planyear")))

        Dim MyNode As WebTreeViewNode
        MyNode = New WebTreeViewNode()
        For Each row As FundCenterParent.FctHRow In Hdatatable


            MyNode.Text = row.Description
            MyNode.Value = row.FundCenter_FundCenterCode

            cnode.Nodes.Add(MyNode)
        Next


        If Len(gpath) >= 10 Then
            Exit Sub
        End If

        Dim hadap2 As New FundCenterParentTableAdapters.UserLikeGpathTableAdapter
        Dim hdt2 As New FundCenterParent.UserLikeGpathDataTable
        Dim sql As String = ""
        Dim prefil As String = ""
        prefil = ""

        Dim pathadd As String = "__"
        'For i = 1 To 4
        sql = ""
        Dim fullpath As String = gpath & pathadd
        If prefil <> "" Then
            sql += " AND fctr_view.FundCenterCode IN (" & prefil & ") "
        End If
        sql += " AND grouppath like '" & fullpath & "' "
        sql += " and USERNAME = '" & Session("users") & "' AND fctr_view.PlanYear = " & Val(Session("PlanYear")) & " AND Fcth.PlanYear = " & Val(Session("PlanYear"))
        hadap2.GetDataByFilter(hdt2, sql)

        For Each row As FundCenterParent.UserLikeGpathRow In hdt2
            If Len(row.grouppath) <= 10 Then
                PlotChild(row.grouppath, MyNode, level + 1)
            End If

        Next

    End Sub

    Sub PlotCmmtNode()

        Dim MyNode As WebTreeViewNode
        MyNode = New WebTreeViewNode()

        Dim adapter As New CmmtHierachyDSTableAdapters.CmmtHierarchiesTableAdapter
        Dim dt As New CmmtHierachyDS.CmmtHierarchiesDataTable
        dt = adapter.GetLevel1(Val(Session("PlanYear")))

        Dim root_id As String

        MyNode.Text = "ทุกรายการ"
        MyNode.Value = "0"
        root_id = "0"

        If dt.Count > 0 Then

            WebTreeView4.Nodes.Add(MyNode)


            For Each item As CmmtHierachyDS.CmmtHierarchiesRow In dt
                Dim MyNode1 As WebTreeViewNode
                Dim dt1 As New CmmtHierachyDS.CmmtHierarchiesDataTable
                MyNode1 = New WebTreeViewNode()
                MyNode1.Text = item.Description
                MyNode1.Value = item.Id
                MyNode.Nodes.Add(MyNode1)
                dt1 = adapter.GetDataByParentID(item.Id, Val(Session("PlanYear")), DropDownList2.SelectedValue)
                If dt1.Count > 0 Then
                    For Each item2 As CmmtHierachyDS.CmmtHierarchiesRow In dt1
                        Dim MyNode2 As WebTreeViewNode
                        Dim dt2 As New CmmtHierachyDS.CmmtHierarchiesDataTable
                        MyNode2 = New WebTreeViewNode()
                        MyNode2.Text = item2.Description
                        MyNode2.Value = item2.Id
                        MyNode1.Nodes.Add(MyNode2)
                        dt2 = adapter.GetDataByParentID(item2.Id, Val(Session("PlanYear")), DropDownList2.SelectedValue)
                        If dt2.Count > 0 Then
                            For Each item3 As CmmtHierachyDS.CmmtHierarchiesRow In dt2
                                Dim MyNode3 As WebTreeViewNode
                                MyNode3 = New WebTreeViewNode()
                                MyNode3.Text = If(item3.IsDescriptionNull, "", item3.Description) & " " & If(item3.IsCmmt_CmmtCodeNull, "", item3.Cmmt_CmmtCode)
                                MyNode3.Value = item3.Id
                                MyNode2.Nodes.Add(MyNode3)
                            Next
                        End If
                    Next


                End If

            Next
        End If
        WebTreeView4.ExpandAll()
    End Sub

    Protected Sub WebCombo1_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles WebCombo1.InitializeDataSource

        Dim adap As New BasicDataTableAdapters.FCTR_Child2TableAdapter
        Dim dt As New BasicData.FCTR_Child2DataTable
        Dim sql = ""
        Dim prefil As String = ""
        'prefil = Session("prefilter")
        Dim enableAllReport As Boolean = False
        enableAllReport = Session("EnableAllReport")
        If enableAllReport Then
            sql += " WHERE 1 = 1 "
           
            sql += " and FundCenters.PlanYear = " & Val(Session("planyear"))
            sql += " and fctr_view.PlanYear = " & Val(Session("planyear"))
            sql += " and FundCenterHierarchies.FundCenterGroup = " & Session("FCTRgroup")
            sql += " and FundCenterHierarchies.PlanYear = " & Val(Session("PlanYear")) & " "
            sql += " and fctr_view.ParentFundCenter = 0 "
            sql += " GROUP BY fctr_view.FundCenterCode, FundCenters.Description, FundCenterHierarchies.Level,fctr_view.ParentFundCenter "

            sql += " ORDER BY FundCenterCode ASC"
        Else
            sql += " WHERE 1 = 1 "
            sql += " AND UserName = '" & Session("users") & "'"
            'If prefil <> "" Then
            '    sql += " AND fctr_view.FundCenterCode IN (" & prefil & ") "
            'End If
            sql += " and FundCenters.PlanYear = " & Val(Session("planyear"))
            sql += " and fctr_view.PlanYear = " & Val(Session("planyear"))
            sql += " and FundCenterHierarchies.FundCenterGroup = " & Session("FCTRgroup")
            sql += " and FundCenterHierarchies.PlanYear = " & Val(Session("PlanYear")) & " "
            sql += " ORDER BY FundCenterCode ASC"
        End If
       
        adap.GetDataByFilter(dt, sql)
        dt.Rows.Add("", "ทุกรายการ", "1", "0")
        dt.DefaultView.Sort = "FundCenterCode"
        e.DataSource = dt



    End Sub

    Protected Sub WebCombo2_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles WebCombo2.InitializeDataSource

        Dim adap As New BasicDataTableAdapters.FCTR_Child2TableAdapter
        Dim dt As New BasicData.FCTR_Child2DataTable
        Dim sql = ""
        Dim prefil As String = ""
        'prefil = Session("prefilter")
        Dim enableAllReport As Boolean = False
        enableAllReport = Session("EnableAllReport")
        If enableAllReport Then
            sql += " WHERE 1 = 1 "
            
            sql += " and FundCenters.PlanYear = " & Val(Session("planyear"))
            sql += " and fctr_view.PlanYear = " & Val(Session("planyear"))
            sql += " and FundCenterHierarchies.FundCenterGroup = " & Session("FCTRgroup")
            sql += " and FundCenterHierarchies.PlanYear = " & Val(Session("PlanYear")) & " "
            sql += " and fctr_view.ParentFundCenter = 0 "
            sql += " GROUP BY fctr_view.FundCenterCode, FundCenters.Description, FundCenterHierarchies.Level,fctr_view.ParentFundCenter "

            sql += " ORDER BY FundCenterCode ASC"
        Else
            sql += " WHERE 1 = 1 "
            sql += " AND UserName = '" & Session("users") & "'"
            'If prefil <> "" Then
            '    sql += " AND fctr_view.FundCenterCode IN (" & prefil & ") "
            'End If

            sql += " and FundCenters.PlanYear = " & Val(Session("planyear"))
            sql += " and fctr_view.PlanYear = " & Val(Session("planyear"))
            sql += " and FundCenterHierarchies.FundCenterGroup = " & Session("FCTRgroup")
            sql += " and FundCenterHierarchies.PlanYear = " & Val(Session("PlanYear")) & " "
            sql += " ORDER BY FundCenterCode ASC"
        End If
       
        adap.GetDataByFilter(dt, sql)
        dt.Rows.Add("", "ทุกรายการ", "1", "0")
        dt.DefaultView.Sort = "FundCenterCode"
        e.DataSource = dt

    End Sub


    Protected Sub toReport_Click(sender As Object, e As ImageClickEventArgs) Handles toReport.Click
        If Val(PlanYearsTxt1.Text) = 0 Then
            ScriptText = "<script language='javascript'>alert('กรุณาระบุปีงบประมาณ ช่องที่1');</script>"
            Exit Sub
        End If
        If VersionCombo1.Value = "" Then
            ScriptText = "<script language='javascript'>alert('กรุณาระบุ Version ช่องที่1');</script>"
            Exit Sub
        End If
        Dim checkstr As String = ""

        If InStr(checkstr, "Y" & PlanYearsTxt1.Text & "V" & VersionCombo1.Text) = 0 Then
            If PlanYearsTxt1.Text <> "" And VersionCombo1.Text <> "" Then
                checkstr += "Y" & PlanYearsTxt1.Text & "V" & VersionCombo1.Text & ","
            End If
        Else
            ScriptText = "<script language='javascript'>alert('ระบุปี และ Version ซ้ำซ้อนกรุณาตรวจสอบ1');</script>"
            Exit Sub
        End If
        If InStr(checkstr, "Y" & PlanYearsTxt2.Text & "V" & VersionCombo2.Text) = 0 Then
            If PlanYearsTxt2.Text <> "" And VersionCombo2.Text <> "" Then
                checkstr += "Y" & PlanYearsTxt2.Text & "V" & VersionCombo2.Text & ","
            End If
        Else
            ScriptText = "<script language='javascript'>alert('ระบุปี และ Version ซ้ำซ้อนกรุณาตรวจสอบ');</script>"
            Exit Sub
        End If
        If InStr(checkstr, "Y" & PlanYearsTxt3.Text & "V" & VersionCombo3.Text) = 0 Then
            If PlanYearsTxt3.Text <> "" And VersionCombo3.Text <> "" Then
                checkstr += "Y" & PlanYearsTxt3.Text & "V" & VersionCombo3.Text & ","
            End If
        Else
            ScriptText = "<script language='javascript'>alert('ระบุปี และ Version ซ้ำซ้อนกรุณาตรวจสอบ');</script>"
            Exit Sub
        End If
        If InStr(checkstr, "Y" & PlanYearsTxt4.Text & "V" & VersionCombo4.Text) = 0 Then
            If PlanYearsTxt4.Text <> "" And VersionCombo4.Text <> "" Then
                checkstr += "Y" & PlanYearsTxt4.Text & "V" & VersionCombo4.Text & ","
            End If
        Else
            ScriptText = "<script language='javascript'>alert('ระบุปี และ Version ซ้ำซ้อนกรุณาตรวจสอบ');</script>"
            Exit Sub
        End If
        If InStr(checkstr, "Y" & PlanYearsTxt5.Text & "V" & VersionCombo5.Text) = 0 Then
            If PlanYearsTxt5.Text <> "" And VersionCombo5.Text <> "" Then
                checkstr += "Y" & PlanYearsTxt5.Text & "V" & VersionCombo5.Text & ","
            End If
        Else
            ScriptText = "<script language='javascript'>alert('ระบุปี และ Version ซ้ำซ้อนกรุณาตรวจสอบ');</script>"
            Exit Sub
        End If
        'If Val(PlanYearsTxt2.Text) = 0 Then
        '    ScriptText = "<script language='javascript'>alert('กรุณาระบุปีงบประมาณ ช่องที่2');</script>"
        '    Exit Sub
        'End If
        'If Val(VersionCombo2.Text) = 0 Then
        '    ScriptText = "<script language='javascript'>alert('กรุณาระบุ Version ช่องที่2');</script>"
        '    Exit Sub
        'End If
        'If Val(PlanYearsTxt3.Text) = 0 Then
        '    ScriptText = "<script language='javascript'>alert('กรุณาระบุปีงบประมาณ ช่องที่3');</script>"
        '    Exit Sub
        'End If
        'If Val(VersionCombo3.Text) = 0 Then
        '    ScriptText = "<script language='javascript'>alert('กรุณาระบุ Version ช่องที่3');</script>"
        '    Exit Sub
        'End If
        'If Val(PlanYearsTxt4.Text) = 0 Then
        '    ScriptText = "<script language='javascript'>alert('กรุณาระบุปีงบประมาณ ช่องที่4');</script>"
        '    Exit Sub
        'End If
        'If Val(VersionCombo4.Text) = 0 Then
        '    ScriptText = "<script language='javascript'>alert('กรุณาระบุ Version ช่องที่4');</script>"
        '    Exit Sub
        'End If
        'If Val(PlanYearsTxt5.Text) = 0 Then
        '    ScriptText = "<script language='javascript'>alert('กรุณาระบุปีงบประมาณ ช่องที่5');</script>"
        '    Exit Sub
        'End If
        'If Val(VersionCombo5.Text) = 0 Then
        '    ScriptText = "<script language='javascript'>alert('กรุณาระบุ Version ช่องที่5');</script>"
        '    Exit Sub
        'End If
        Session.Remove("year")
        Session.Add("year", PlanYearsTxt1.Text)

        Session.Remove("version")
        Session.Add("version", VersionCombo1.Text)

        Session.Remove("FundcenterAll")

        'Add by Orn 28/4/2558
        Dim useradap As New UserDSTableAdapters.UsersTableAdapter()
        Dim userDS As New UserDS.UsersDataTable
        userDS = useradap.GetDataByUsername(Session("users"))
        Dim enableAllUser As Boolean = False
        If userDS.Rows.Count > 0 Then
            If userDS(0)("Enable_All_Report_Flag").ToString() <> "" Then
                enableAllUser = userDS(0)("Enable_All_Report_Flag")
            End If
        End If
        If TabContainer1.ActiveTab.ID = TabPanel1.ID Then
            Session.Remove("FCTRmode")
            Session.Add("FCTRmode", "1")
            Session.Remove("FundcenterAll")
            If enableAllUser = True Then
                Session.Add("FundcenterAll", FctrClass.GetFromToFundCenterReport(WebCombo1.Value, WebCombo2.Value, Val(Session("year"))))
            Else
                'If WebCombo1.Value <> "" And WebCombo2.Value = "" Then
                '    Session.Add("FundcenterAll", FctrClass.GetFromToFundCenterReport(WebCombo1.Value, WebCombo1.Value, Val(Session("year"))))
                'ElseIf WebCombo1.Value = "" And WebCombo2.Value <> "" Then
                '    Session.Add("FundcenterAll", FctrClass.GetFromToFundCenterReport(WebCombo2.Value, WebCombo2.Value, Val(Session("year"))))
                'Else
                '    Session.Add("FundcenterAll", FctrClass.GetUserFundCenter(Session("users"), Val(Session("year"))))
                'End If
                'Edit by Orn 10/08/2558
                Session.Add("FundcenterAll", FctrClass.GetUserFundCenterFromTo(Session("users"), Val(Session("year")), WebCombo1.Value, WebCombo2.Value))
            End If
        ElseIf TabContainer1.ActiveTab.ID = TabPanel2.ID Then
            Session.Remove("FCTRmode")
            Session.Add("FCTRmode", "2")
            If WebCombo3.Value <> "" Then
                If WebCombo3.Value <> 0 Then
                    Session.Add("FundcenterAll", FctrClass.GetSubFundCenterrReport(WebCombo3.Value, Session("users"), Val(Session("year")), ""))
                Else
                    If enableAllUser = True Then
                        Session.Add("FundcenterAll", FctrClass.GetUserFundCenter(Val(Session("year"))))
                    Else
                        Session.Add("FundcenterAll", FctrClass.GetUserFundCenter(Session("users"), Val(Session("year"))))
                    End If
                End If
            Else
                If enableAllUser = True Then
                    Session.Add("FundcenterAll", FctrClass.GetUserFundCenter(Val(Session("year"))))
                Else
                    Session.Add("FundcenterAll", FctrClass.GetUserFundCenter(Session("users"), Val(Session("year"))))
                End If
            End If
        End If
        'End Add by Orn 28/4/2558

        'If TabContainer1.ActiveTab.ID = TabPanel1.ID Then
        '    Session.Remove("FCTRmode")
        '    Session.Add("FCTRmode", "1")
        '    'Session.Add("FundcenterS", WebCombo1.Value)
        '    'Session.Add("FundcenterE", WebCombo2.Value)
        '    Session.Remove("FundcenterAll")
        '    If WebCombo1.Value <> "" And WebCombo2.Value <> "" Then
        '        Session.Add("FundcenterAll", FctrClass.GetFromToFundCenter(WebCombo1.Value, WebCombo2.Value, Session("users"), Val(Session("year"))))
        '        'Response.Write(FctrClass.GetFromToFundCenter(WebCombo1.Value, WebCombo2.Value, Session("users")))
        '    ElseIf WebCombo1.Value <> "" And WebCombo2.Value = "" Then
        '        Session.Add("FundcenterAll", FctrClass.GetFromToFundCenter(WebCombo1.Value, WebCombo1.Value, Session("users"), Val(Session("year"))))
        '        'Response.Write(FctrClass.GetFromToFundCenter(WebCombo1.Value, WebCombo1.Value, Session("users")))
        '    ElseIf WebCombo1.Value = "" And WebCombo2.Value <> "" Then
        '        Session.Add("FundcenterAll", FctrClass.GetFromToFundCenter(WebCombo2.Value, WebCombo2.Value, Session("users"), Val(Session("year"))))
        '        'Response.Write(FctrClass.GetFromToFundCenter(WebCombo2.Value, WebCombo2.Value, Session("users")))
        '    Else
        '        Session.Add("FundcenterAll", FctrClass.GetUserFundCenter(Session("users"), Val(Session("year"))))
        '    End If


        'ElseIf TabContainer1.ActiveTab.ID = TabPanel2.ID Then
        '    Session.Remove("FCTRmode")
        '    Session.Add("FCTRmode", "2")
        '    If WebCombo3.Value <> "" Then
        '        Session.Add("FundcenterAll", FctrClass.GetSubFundCenter(WebCombo3.Value, Session("users"), Val(Session("year")), ""))
        '    Else
        '        Session.Add("FundcenterAll", FctrClass.GetUserFundCenter(Session("users"), Val(Session("year"))))
        '    End If

        'End If

        If TabContainer2.ActiveTab.ID = TabPanel3.ID Then
            Session.Remove("CmmtCodeS")
            Session.Add("CmmtCodeS", CmmtCodeS2.Value)

            Session.Remove("CmmtCodeE")
            Session.Add("CmmtCodeE", CmmtCodeE2.Value)

            Session.Remove("CmmtMode")
            Session.Add("CmmtMode", "1")
        ElseIf TabContainer2.ActiveTab.ID = TabPanel4.ID Then
            Session.Remove("CmmtParent")
            Session.Add("CmmtParent", WebCombo4.Value.ToString)

            Session.Remove("CmmtMode")
            Session.Add("CmmtMode", "2")
        End If


        Session.Remove("year1")
        Session.Add("year1", PlanYearsTxt1.Text)
        Session.Remove("year2")
        Session.Add("year2", PlanYearsTxt2.Text)
        Session.Remove("year3")
        Session.Add("year3", PlanYearsTxt3.Text)
        Session.Remove("year4")
        Session.Add("year4", PlanYearsTxt4.Text)
        Session.Remove("year5")
        Session.Add("year5", PlanYearsTxt5.Text)


        Session.Remove("version1")
        Session.Add("version1", VersionCombo1.Value)
        Session.Remove("version2")
        Session.Add("version2", VersionCombo2.Value)
        Session.Remove("version3")
        Session.Add("version3", VersionCombo3.Value)
        Session.Remove("version4")
        Session.Add("version4", VersionCombo4.Value)
        Session.Remove("version5")
        Session.Add("version5", VersionCombo5.Value)


        If Val(RadioButtonList1.SelectedValue) = 1 Then
            ScriptText = "<script language='javascript'>openpop1();</script>"
        ElseIf Val(RadioButtonList1.SelectedValue) = 2 Then
            ScriptText = "<script language='javascript'>openpop2();</script>"
        ElseIf Val(RadioButtonList1.SelectedValue) = 3 Then
            ScriptText = "<script language='javascript'>openpop3();</script>"
        Else
            ScriptText = "<script language='javascript'>openpop();</script>"
        End If

    End Sub


    Protected Sub WebCb_productFrom_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs)
        Dim adapter As New Data_ReportTableAdapters.ProductsTableAdapter
        Dim data As New Data_Report.ProductsDataTable

        data = adapter.GetDataByPlanYear(Val(Session("planyear")))
        ' data.Rows.Add("0", "ทุกรายการ", "1", "0")
        data.DefaultView.Sort = "ProductCode"
        e.DataSource = data

    End Sub

    Protected Sub VersionCombo_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles VersionCombo1.InitializeDataSource, VersionCombo2.InitializeDataSource, VersionCombo3.InitializeDataSource, VersionCombo4.InitializeDataSource, VersionCombo5.InitializeDataSource
        Dim adap As New MasterDataSet2TableAdapters.BudgetVersionsTableAdapter
        Dim dt As New MasterDataSet2.BudgetVersionsDataTable
        dt = adap.GetData
        e.DataSource = dt
    End Sub

    Protected Sub CmmtCodeS2_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs)
        Dim adap As New Data_ReportTableAdapters.CmmtDataTableAdapter
        Dim dt As New Data_Report.CmmtDataDataTable
        dt = adap.GetData(Session("PlanYear"))

        e.DataSource = dt
    End Sub
    Protected Sub CmmtCodeE2_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs)
        Dim adap As New Data_ReportTableAdapters.CmmtDataTableAdapter
        Dim dt As New Data_Report.CmmtDataDataTable
        dt = adap.GetData(Session("PlanYear"))

        e.DataSource = dt
    End Sub

    Protected Sub WebCombo3_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles WebCombo3.InitializeDataSource

        Dim adap As New FundCenterParentTableAdapters.SelectorTableAdapter
        Dim dt As New FundCenterParent.SelectorDataTable
        Dim dt2 As New FundCenterParent.SelectorDataTable
        Dim sql = ""
        'Dim prefil As String = ""
        'prefil = Session("prefilter")
        Dim enableAllReport As Boolean = False
        enableAllReport = Session("EnableAllReport")
        If enableAllReport Then
            sql += " WHERE 1 = 1 "
            sql += " AND fctr_view.PlanYear = " & Val(Session("PlanYear")) & " AND FctH.PlanYear = " & Val(Session("PlanYear"))
          
            sql += " and FctH.fundcentergroup = " & Session("FCTRgroup")
            sql += " GROUP BY  FctH.Description, FctH.FundCenter_FundCenterCode, FctH.ParentFundCenterHierarchy_Id"
            sql += ", FctH.grouppath,  FctH.pathname, FctH.planyear "

            sql += " ORDER BY Grouppath"
        Else
            sql += " WHERE 1 = 1 "
            sql += " and USERNAME = '" & Session("users") & "' AND fctr_view.PlanYear = " & Val(Session("PlanYear")) & " AND FctH.PlanYear = " & Val(Session("PlanYear"))
            'If prefil <> "" Then
            '    sql += " AND fctr_view.FundCenterCode IN (" & prefil & ") "
            'End If
            sql += " and FctH.fundcentergroup = " & Session("FCTRgroup")
            sql += " ORDER BY Grouppath"
        End If
       
        adap.GetDataByFilter(dt2, sql)
        dt.Rows.Add("ทุกรายการ", "0", 0, "0", Val(Session("PlanYear")), "ทุกรายการ")
        dt.Merge(dt2)
        'dt.DefaultView.Sort = "FundCenter_FundCenterCode"
        e.DataSource = dt



    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
        Session("FCTRgroup") = DropDownList1.SelectedValue
        WebCombo1.ClearCachedDataSource()
        WebCombo1.DataBind()
        WebCombo2.ClearCachedDataSource()
        WebCombo2.DataBind()
        WebCombo3.ClearCachedDataSource()
        WebCombo3.DataBind()
    End Sub
End Class
